#include "App/gyro_algorithm.h"
#include "App/line_algorithm.h"
#include "App/mv_serial_data_parse.h"
#include "Components/ATK_MS901M/atk_ms901m.h"
#include "Components/algorithm.h"
#include "Components/basic.h"
#include "Components/line_patrol.h"
#include "Components/motion.h"
#include "Components/motor.h"
#include "Components/oled_hardware_i2c.h"
#include "Components/servo.h"
#include "Components/simple_json.h"
#include <ti/driverlib/m0p/dl_interrupt.h>

#define TAG "ADC_TEST"

// bool gCheckADC = false;

int main(void) {

  SYSCFG_DL_init();
  SysTick_Init();
  uart_init();
  OLED_Init();

  //NVIC_EnableIRQ(BUTTON_ADC_INST_INT_IRQN);

  uint16_t adcResult;
 // gCheckADC = false;

  /* Confirm VREF has settled before triggering ADC12 conversion */
  while (DL_VREF_CTL1_READY_NOTRDY == DL_VREF_getStatus(VREF))
    ;

  while (1) {
    delay(100);
    DL_ADC12_startConversion(BUTTON_ADC_INST);

    // while (false == gCheckADC) {
    //   __WFE();
    // }

    

    adcResult = DL_ADC12_getMemResult(BUTTON_ADC_INST, DL_ADC12_MEM_IDX_0);

    sprintf(__str_all, "adc=%d", adcResult);
    OLED_ShowString(0, 0, __str_all, 16);

   // gCheckADC = false;
    DL_ADC12_enableConversions(BUTTON_ADC_INST);
  }
}

// void BUTTON_ADC_INST_IRQHandler(void) {
//   switch (DL_ADC12_getPendingInterrupt(BUTTON_ADC_INST)) {
//   case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
//     gCheckADC = true;
//     break;
//   default:
//     break;
//   }
// }